<?php
//--------------------------------------------------
//	Filename: index.php
//--------------------------------------------------
//		Information:
// This is the index file. Every file/page is 
// included through this file.
//--------------------------------------------------
define('IN_INDEX', true);
include('inc/header.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<head>
	<?php
    if(checkSession())
				{
				?>
                <link type="text/css" href="chat/cometchatcss.php" rel="stylesheet" charset="utf-8">
                <script type="text/javascript" src="chat/cometchatjs.php" charset="utf-8"></script>
				<?php //iso-8859-1
				}
				?>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title><?php echo translate('header_text'); ?> - <?php echo translate('header_undertext');  ?></title>
        <META name ="description" content ="<?php echo translate('meta_name'); ?>" />
  		<META Name="keywords" content="<?php echo translate('meta_keywords'); ?>" />
		<link href="style.css" rel="stylesheet" type="text/css" />
        <link rel="shortcut icon" href="favicon.ico" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
        
        
        <script type="text/javascript" src="jscript/emptyonclick.js"></script>
        <script type="text/javascript" src="jscript/skin.js" charset="utf-8"></script>
        <script type="text/javascript" src="jscript/tiny_mce/tiny_mce.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
        <link href="http://jqueryui.com/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
	</head>
<script type="text/javascript">
	sys.action = <?php echo json_encode($_GET);?>
</script>
<body>
<?php include_once("analyticstracking.php") ?>

    <!-- wrap START -->
    <div id="wrap">

	<!-- container START -->
<?php
if($include_sidebar)
{
	?><div id="container"><?php
}
else
{
	?><div id="container" class="one-column"><?php
}
if(isset($_REQUEST['error']))
{
	switch($_REQUEST['error'])
	{
		case 0: // Missmatch email/password
			$MESSAGE['login_status'] = 'invalidlogin';
			break;
		case 1:	// Account disabled
			$MESSAGE['login_status'] = 'userisnotactive';
			break;
		default: // Nothing to report
			$MESSAGE['login_status'] = '';
			break;
	}
}
?>

			<!-- header START -->
			<div id="header">

				<!-- banner START -->
					<?php 
					if($VISITOR_COUNTRY == 'NO')
					{
					?>
          			<a href='index.php?action=home'><img style="padding-left: 15px; padding-top: 5px;" src="logo_s.png" alt="logo"></a>
                    <?php
					}
					elseif(checkSession())
					{
						if($USER->getLang() == 'no')
						{
							?>
                           	<a href='index.php?action=home'><img style="padding-left: 15px; padding-top: 5px;" src="logo_s.png" alt="logo"></a>
                            <?php
						}
						else
						{
							echo "<div id='caption'>
							<h1 id='title'><a href='index.php?action=home'>". translate('header_text') ."</a></h1>
							<div id='tagline'><a href='index.php?action=home'>". translate('header_undertext') . "</a></div>
							</div>";
						}
					}
					elseif($VISITOR_COUNTRY != 'NO')
					{
                    	echo "<div id='caption'>
						<h1 id='title'><a href='index.php?action=home'>". translate('header_text') ."</a></h1>
						<div id='tagline'><a href='index.php?action=home'>". translate('header_undertext') . "</a></div>
						</div>";
					}
					?>				
				<!-- banner END -->
                
				<div class="fixed"></div>
			</div>			
			<!-- header END -->

			<!-- navigation START -->
			<div id="navigation">
            
				<!-- menus START -->
				<ul id="menus">
					<?php print_menu($MENU_LIST); ?>
					<li><a class="lastmenu" href="javascript:void(0);"></a></li>
				</ul>
				<!-- menus END -->
                <?php
				if( !checkSession() )
				{
				?>
                <div class="login" style="text-align: right;">
                    <form method="post" action="index.php">
                    <?php
                            if(isset($MESSAGE['login_status']) && $MESSAGE['login_status'] != "")
							{
								echo "<span style='font-size:9px;' class=\"error\">" . translate($MESSAGE['login_status']) . " -></span>";
							}
							else
							{
								echo "";
							}
							?>
					            
					                <input style="login_table" type="text" id="login_email" name="login_email" onfocus="EmptyOnClick('login_email');" value="<?php echo translate('email'); ?>" />
					            
					                <input type="password" id="login_password" name="login_password" onfocus="EmptyOnClick('login_password');" value="<?php echo translate('password'); ?>" />
					            
                          <input style="margin-top:5px; margin-right:5px; font-weight:bold;" id="submitbox" type="submit" name="login_submit" value=" <?php echo translate('login'); ?> " />
				</form>
                </div>
				<?php
				} 
				else
				{
					
				?>
				<?php
				if(!checkSession())
				{
					?>
    
				<!-- loginmessage START -->
                    <?php 
				if($MESSAGE['login_status'] != "")
				{
					echo "<span style='font-size:9px;' class=\"error\">" . $MESSAGE['login_status'] . "</span>";
				}
				?>	
				<!-- loginmessage END -->
                
				<?php
				}
				else
				{
					?>
				<div style="text-align: right;">
            		<form method="post" action="index.php?logout">
						<?php echo translate('himesssage') . " <b>" . $USER->getFirstname() . "</b>";
						if($USER->getRank() == 5)
						{	
							echo " (Admin)";
						}
						if($USER->getRank() == 3)
						{	
							echo " (Moderator)";
						}
						if($USER->getRank() == 2)
						{	
							echo " (Premium)";
						}
						
						$unread_pm = countUnreadPM($USER->getId());
						$friendspending = countFriendPending($USER->getId());
						//Display and You have if there is a messsage and/or a friend request
						if($unread_pm > 0 || $friendspending > 0)
						{
							echo ", ". translate('youhave') . " ";
						}
						
						//Display PM if there is (1)
						if($unread_pm == 1)
							{
							$you_got_new_pm = str_replace('VAR1', "<b>" . $unread_pm . "</b>", $LANG['you_got_new_pm']);
							echo "<a href=\"index.php?action=profile&sub=pm\"><img src='img/pm_unread2.png' /> " . $you_got_new_pm . "</a>";
							}

						//Display PM if there is more than (1)
						if($unread_pm >= 2)
							{
							$you_got_new_pm = str_replace('VAR1', "<b>" . $unread_pm . "</b>", $LANG['you_got_new_pm2']);
							echo "<a href=\"index.php?action=profile&sub=pm\"><img src='img/pm_unread2.png' /> " . $you_got_new_pm . "</a>";
							}
							
						//Display and and if there is a messsage and a friend request
						if($unread_pm > 0 && $friendspending > 0)
						{
							echo " ". translate('and') . " ";
						}
						
						//Pending friend request
						if($friendspending == 1)
							{
							echo "<a href=\"index.php?action=profile&sub=friends\"><img src='img/user_add.png' /> <b>" . $friendspending . "</b> ". translate('friendrequest').  " </a>";
							}
							
						//Pending friend request from more then (1)
						if($friendspending >= 2)
							{
							echo "<a href=\"index.php?action=profile&sub=friends\"><img src='img/user_add.png' /> <b>" . $friendspending . "</b> ". translate('friendrequest2').  " </a>";
							}
						?>
                    	<input style="margin-top:5px; margin-right:5px; font-weight:bold;" type="submit" value=" <?php echo translate('logout'); ?> " />
		  			</form>
          		</div>
          			<?php
				}
				
				if(count($SUBMENU_LIST) > 0)
				{
					?>
                <div class="fixed"></div>
                
                <!-- submenu START -->
				<ul id="submenu">
					<?php print_submenu($SUBMENU_LIST); ?>
				</ul>
				<!-- submenu END -->
                	<?php
				}}
				?>
                
                
    			<div class="fixed"></div>
			</div>
			<!-- navigation END -->

			<!-- content START -->
			<div id="content">

				<!-- main START -->
				<div id="main">
                	<?php include($INCLUDE_PAGE); ?>
					<div class="fixed">
					</div>
				</div>
				<!-- main END -->
<?php
if($include_sidebar)

{
	?>
				<!-- sidebar START -->
				<div id="sidebar">

					<div id="centersidebar">
						Sidebar
						<!-- sidebar east START -->
						<div id="eastsidebar" class="sidebar">
						</div>
						<!-- sidebar east END -->

						<!-- sidebar west START -->
						<div id="westsidebar" class="sidebar">
						</div>
						<!-- sidebar west END -->
						<div class="fixed"></div>
					</div>
                    
					<!-- sidebar south START -->
					<div id="southsidebar" class="sidebar">

						<!-- meta -->
						<div class="widget">
                        </div>
                    </div>
					<!-- sidebar south END -->

				</div>
				<!-- sidebar END -->
	<?php
}
?>
			</div>
			<!-- content END -->

			<div class="fixed">
			</div>
            
			<!-- footer START -->
			<div id="footer">
				<a id="gotop" href="#" onclick="MGJS.goTop();return false;"><?php echo translate('top'); ?></a>

				<div align="center" id="copyright">
                <?php echo translate('header_text'); ?> <a href="http://en.wikipedia.org/wiki/Copyright">&copy;</a> <?php echo translate('copyrightyear'); ?> - 
                <?php
				if(checkSession())
				{
				$lang = $USER->getLang(); 
                foreach($LANG_LIST as $key => $val)
                		{
                			if($val['iso'] == $lang)
                			{
                				echo "<a href='index.php?action=profile&sub=edit_general'>".translate($val['local_name']) . "</a> -";
                			}
						}
		       	}
				?>
                
                <a href="Changelog.txt"><?php echo translate('curversion'); ?></a> - 
                <a href="mailto:feedback@thepowerlifters.com?Subject=<?php echo translate('contact'); ?>"><?php echo translate('contact'); ?></a> - 
                <a href="index.php?action=about"><?php echo translate('about'); ?></a> 
                <?php
				if(checkSession())
				{
				?>
                 -  <img src="./img/user_friends.png" alt="<?php echo translate('onlineusers'); ?>" /><a href="index.php?action=home&sub=stats"><?php echo getActiveUsers(); ?></a></div>
                <?php
				}
				?>
                </div>

			</div>
			<!-- footer END -->

		</div>
		<!-- container END -->

	</div>
	<!-- wrap END -->
</body>
</html>
<?php
$db->sql_close();
?>